|
|
|
|
|
|
|
Figure 2.13
Program BkMode shows how to use API
functions to control pattern fills. |
|
|
|
 |
|
|
|
|
Private Declare Function SetPolyFillMode Lib "gdi32" _
Alias "SetPolyFillMode" (ByVal hdc As Long, _
ByVal nPolyFillMode As Long) As Long |
|
|
|
|
|
|
|
|
When the fill mode is ALTERNATE, the system fills every other section in the polygon along each horizontal scan line. To see how this works, trace a horizontal line from the left edge of the screen until it reaches a segment in a polygon. The system begins filling at that point. When it reaches another segment, the system stops filling. If it later hits a third segment, it starts filling again, and so on until it reaches the right side of the screen. |
|
|
|
|
|
|
|
|
When the fill mode is WINDING, the system uses the direction in which the polygons' segments were drawn to decide which parts of the shape to fill. Start with a counter initialized to zero and trace a scan line from the left side of the screen as before. This time, whenever you meet one of the polygon's segments, add one to the counter if that segment was drawn in the clockwise direction and subtract one if the segment was drawn in the counterclockwise direction. Then, if the counter is not zero, start filling. If the counter is zero, stop filling. |
|
|
|
|
|
|
|
|
Example program FillMode, shown in Figure 2.14, uses the PolyPolygon function to draw a star and a rectangle several times. The program draws its top three pictures with fill mode ALTERNATE and its bottom three with fill mode WINDING. The two pictures on the left show a star drawn in the counterclockwise direction. The middle pictures contain a star and a rectangle, both drawn counterclockwise. In the pictures on the right, the rectangle is drawn in the clockwise direction. |
|
|
|
|
|
|
|
|
When you are drawing only a single polygon, the difference between the two styles is relatively easy to understand. The WINDING fill mode fills all of the polygon while the ALTERNATE mode may result in some unfilled sections. When more than one polygon is involved, things can become confusing. In that case, it may be easiest to write a program and try drawing the polygons clockwise and counterclockwise using the different fill modes until you get the result you want. |
|
|
|
|
|